# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

panda_ecmascript_add_gtest(
    NO_CORES
    NAME debug_api_tests_ecma
    SOURCES
        test_list.cpp
        launcher.cpp
    LIBRARIES
        debugtest
    INCLUDE_DIRS
        ${PANDA_ROOT}
    SANITIZERS
        ${PANDA_SANITIZERS_LIST}
)

add_dependencies(debug_api_tests_ecma arkstdlib)

panda_target_compile_definitions(debug_api_tests_ecma
                           PUBLIC
                           DEBUG_LIBRARY_PATH="$<TARGET_FILE_NAME:debugtest>"
                           PANDA_STD_LIB="${PANDA_BINARY_ROOT}/pandastdlib/arkstdlib.abc")

set(JS_SOURCES
    Sample
    GetVariable
    SetVariable
    GetFrame
    FramePop
    RestartFrame
    SetNotification
    ExceptionTest
)

foreach(c ${JS_SOURCES})
    add_custom_target(es2panda_convert_${c}
        COMMAND echo "Convert js: ${c} to js/${c}.abc"
        COMMAND mkdir -p "${CMAKE_CURRENT_BINARY_DIR}/js/"
        COMMAND ${PANDA_RUN_PREFIX} $<TARGET_FILE:es2panda> --opt-level=0 --debug-info ${CMAKE_CURRENT_SOURCE_DIR}/js/${c}.js --output ${CMAKE_CURRENT_BINARY_DIR}/js/${c}.abc
    )
    add_dependencies(debug_api_tests_ecma_gtests es2panda_convert_${c})
endforeach()

add_gtests(
    arkruntime_ecmascript_options_test
    options_test/options_test.cpp
)
